package com.lzq.model.builder;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/17 16:37
 * @updateUser : modify
 * @updateTime : 2022/11/17 16:37
 * @updateRemark :
 */
public abstract class BikeBuilder {
    protected Bike bike = new Bike();

    /**
     * 构建车架
     */
    public abstract void buildFrame();

    /**
     * 构建车座
     */
    public abstract void buildSeat();

    /**
     * 创建自行车对象
     *
     * @return Bile
     */
    public abstract Bike createBike();
}

class MoBileBike extends BikeBuilder {

    @Override
    public void buildFrame() {
        bike.setFrame("mobile frame");
    }

    @Override
    public void buildSeat() {
        bike.setSeat("mobile seat");
    }

    @Override
    public Bike createBike() {
        return bike;
    }
}

class OfoBike extends BikeBuilder {

    @Override
    public void buildFrame() {
        bike.setFrame("ofo frame");
    }

    @Override
    public void buildSeat() {
        bike.setSeat("ofo seat");
    }

    @Override
    public Bike createBike() {
        return bike;
    }
}

class Director {
    private BikeBuilder builder;

    public Director(BikeBuilder builder) {
        this.builder = builder;
    }

    public Bike construct() {
        builder.buildFrame();
        builder.buildSeat();
        return builder.createBike();
    }
}

class Test {
    public static void main(String[] args) {
        Director director = new Director(new MoBileBike());
        Bike bike = director.construct();
        System.out.println(bike.getFrame() + " <<<====>>> " + bike.getSeat());
    }
}